package com.orhon.smartcampus.modules.systemctl.entity;

import java.util.Date;
import java.util.List;

import javax.persistence.*;

import org.hibernate.annotations.NotFound;
import org.hibernate.annotations.NotFoundAction;
import org.hibernate.annotations.Where;

import com.orhon.smartcampus.modules.base.entity.Grades;
import com.orhon.smartcampus.modules.base.entity.Schools;
import com.orhon.smartcampus.modules.base.entity.Subjects;

import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Setter;
@Setter
@Getter
@EqualsAndHashCode
@Entity
@Table(name = "systemctl_org_departments", schema = "smartcloud", catalog = "")
public class OrgDepartments {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "id", nullable = false)
    private Long id;
    @Column(name = "department_name", nullable = true)
    private String departmentName;
    @Column(name = "department_order", nullable = true)
    private Integer departmentOrder;
    @Column(name = "type", nullable = false, length = 191)
    private String type;
    @Column(name = "group_type", nullable = true, length = 191)
    private String groupType;
    @Column(name = "status", nullable = true)
    private Integer status;
    @Column(name = "created_at", nullable = false)
    private Date createdAt;
    @Column(name = "updated_at", nullable = true)
    private Date updatedAt;
    @Column(name = "deleted_at", nullable = true)
    private Date deletedAt;

    @ManyToOne
    @Where(clause = "ISNULL(deleted_at)")
    @JoinColumn(name = "parent_id", referencedColumnName = "id")
    @NotFound(action=NotFoundAction.IGNORE)
    private OrgDepartments systemctlOrgDepartmentsByParentId;

    @OneToMany(fetch = FetchType.LAZY)
    @Where(clause = "ISNULL(deleted_at)")
    @JoinColumn(name = "parent_id", referencedColumnName = "id")
    @NotFound(action=NotFoundAction.IGNORE)
    private List<OrgDepartments> childreen;


    @ManyToOne
    @Where(clause = "ISNULL(deleted_at)")
    @NotFound(action=NotFoundAction.IGNORE)
    @JoinColumn(name = "school_id", referencedColumnName = "id")
    private Schools baseSchoolsBySchoolId;



    //年级
    @ManyToMany(cascade = CascadeType.ALL,  fetch = FetchType.EAGER)
    @Where(clause = "ISNULL(deleted_at)")
    @NotFound(action=NotFoundAction.IGNORE)
    @JoinTable(
            name = "systemctl_org_department_grade_relation",
            joinColumns = { @JoinColumn(name = "department_id")},
            inverseJoinColumns = { @JoinColumn(name = "grade_id")}
    )
    List<Grades> grades;

    //学科
    @ManyToMany(cascade = CascadeType.ALL,  fetch = FetchType.EAGER)
    @Where(clause = "ISNULL(deleted_at)")
    @NotFound(action=NotFoundAction.IGNORE)
    @JoinTable(
            name = "systemctl_org_department_subject_relation",
            joinColumns = { @JoinColumn(name = "department_id")},
            inverseJoinColumns = { @JoinColumn(name = "subject_id")}
    )
    private List<Subjects> subjects;



    //职务
    @ManyToMany(cascade = CascadeType.ALL,  fetch = FetchType.EAGER)
    @Where(clause = "ISNULL(deleted_at)")
    @NotFound(action=NotFoundAction.IGNORE)
    @JoinTable(
            name = "systemctl_org_department_duty_relation",
            joinColumns = { @JoinColumn(name = "department_id")},
            inverseJoinColumns = { @JoinColumn(name = "duty_id")}
    )
    List<OrgDuties> duties;


}
